// 基于 SnowLang Project (https://gitee.com/jcnc-org/snow) 的衍生作品
// 原始版权归属: Copyright © 2025 Ke Xu (Luke)
// 本实现版权归属: Copyright © 2025 Sany
// 遵循 Apache License 2.0 授权
package engine

import (
	"gitee.com/xntk2381/cc/vm/utils"
)

var VMCommandExecutor = NewVMCommandExecutor()

// VMCommandExecutor 虚拟机指令执行器
type vMCommandExecutor struct{}

// NewVMCommandExecutor 创建新的VMCommandExecutor实例
func NewVMCommandExecutor() *vMCommandExecutor {
	return &vMCommandExecutor{}
}

// ExecuteInstructions 执行虚拟机指令
func (e *vMCommandExecutor) ExecuteInstructions(vmEngine *VirtualMachineEngine, instructions []string) {
	defer func() {
		if err := recover(); err != nil {
			utils.LogError("Error while executing instructions: " + err.(error).Error())
		}
	}()

	vmEngine.Execute(instructions)
}
